//
//  HomePageViewController.m
//  吃喝玩乐一起嗨
//
//  Created by CEZ on 14-10-15.
//  Copyright (c) 2014年 CEZ. All rights reserved.
//

#import "HomePageViewController.h"
#import "MenuTableViewCell.h"
#import "ActivitiesTableViewCell.h"
#import "GuessWhatYouLikeTableViewCell.h"

@interface HomePageViewController ()<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)UISearchBar *searchBar;
@end

@implementation HomePageViewController
- (void)dealloc
{
    [_myButton release];
    [_locateButton release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView];
    [self createSearchBar];
    [self createMyButton];
    [self createLocateButton];
}

- (void)createMyButton
{
    _myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _myButton.layer.cornerRadius = 5;
    _myButton.frame = CGRectMake(10, 0, 60, 40);
    _myButton.backgroundColor = [UIColor cyanColor];
    [_myButton setTitle:@"我的" forState:UIControlStateNormal];
    [self.navigationController.navigationBar addSubview:_myButton];
    
}
- (void)createLocateButton
{
    _locateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _locateButton.layer.cornerRadius = 5;
    _locateButton.frame = CGRectMake(305, 0, 60, 40);
    _locateButton.backgroundColor = [UIColor redColor];
    [_locateButton setTitle:@"定位" forState:UIControlStateNormal];
    [self.navigationController.navigationBar addSubview:_locateButton];

}
- (void)createSearchBar
{
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(75, 20, 220, 0)];
    [_searchBar setBarStyle:UIBarStyleDefault];
    //    [_searchBar setBarStyle:UIBaselineAdjustmentNone];
    _searchBar.backgroundColor = [UIColor whiteColor];
    _searchBar.layer.cornerRadius = 10;
    _searchBar.layer.borderWidth = 0.1;
    [self.navigationController.navigationBar addSubview:_searchBar];
    [_searchBar release];
}

- (void)createTableView
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 750, 750 - 64 )style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView setShowsHorizontalScrollIndicator:NO];
    [_tableView setShowsVerticalScrollIndicator:NO];
    [self.view addSubview:_tableView];
    [_tableView release];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 3;
    }else {
        return 3;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.001;
    }else if (section == 2){
        return 20;
    }
    return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return @"猜你喜欢";
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 210;
    }else if (indexPath.section == 1){
        return 160;
    }else if (indexPath.section == 2){
        return 150;
    }else{
        return 100;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *identifier = @"menu";
        MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[[MenuTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]autorelease];
        }
        return cell;
    }else if (indexPath.section == 1) {
        static NSString *identifier = @"activities";
        ActivitiesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[[ActivitiesTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]autorelease];
        }
        return cell;
    }else {
        static NSString *identifier = @"guessWhatYoulike";
        GuessWhatYouLikeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[[GuessWhatYouLikeTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]autorelease];
        }
        return cell;
    }
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]autorelease];
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
